package com.example.cuibo.errordealwith;

import java.io.File;
import java.io.IOException;
import java.util.Scanner;

/**
 * Created by cuibo on 2017/11/1.
 */

public class File创建 {

    private void xxx() throws IOException{
        File file = new File("YY.text");// 项目的工程
        boolean isScess =  file.createNewFile();// 创建目录
        file.delete();
        File file2 = new File("zzz");
        boolean b2 = file2.createNewFile();


        // 创建文件夹
        File dir1 = new File("aaa");
        boolean a = dir1.mkdir();

        // 删除重名文件
        File file3 = new File("aa");
        file.listFiles();
        file3.canRead();
        file.isHidden();
        file.exists();

        File file4 = getFile();
    }
    public static File getFile(){
        Scanner sc = new Scanner(System.in);
        System.out.print("请输入一个文件路径");
        while (true){
            String lin = sc.next(); // 将键盘录入存储在line中
            File file = new File(lin);
            if (!file.exists()){
                System.out.print("文件路径不存在");
            }else if (file.isDirectory()){
                System.out.print("输入的是文件夹");
            }else {
                return file;
            }
        }
    }
}
